using System;
using ComponentFactory.Krypton.Toolkit;
using RaGE_JD.Properties;

namespace RaGE_JD
{
    public partial class ExprCalc : KryptonForm
    {
        public ExprCalc()
        {
            InitializeComponent();
        }

        private void BtnCalcCloseClick(object sender, EventArgs e)
        {
            Dispose();
        }

        private void BtnKey0Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.ZERO;
            MainWindow.Encode += Resources.ZERO;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey1Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.ONE;
            MainWindow.Encode += Resources.ONE;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey2Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.TWO;
            MainWindow.Encode += Resources.TWO;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey3Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.THREE;
            MainWindow.Encode += Resources.THREE;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey4Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.FOUR;
            MainWindow.Encode += Resources.FOUR;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey5Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.FIVE;
            MainWindow.Encode += Resources.FIVE;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey6Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.SIX;
            MainWindow.Encode += Resources.SIX;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey7Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.SEVEN;
            MainWindow.Encode += Resources.SEVEN;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey8Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.EIGHT;
            MainWindow.Encode += Resources.EIGHT;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKey9Click(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.NINE;
            MainWindow.Encode += Resources.NINE;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyPeriodClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.PERIOD;
            MainWindow.Encode += Resources.PERIOD;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyEqualClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.EQUAL;
            MainWindow.Encode += Resources.EQUAL;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyLessClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.LESS;
            MainWindow.Encode += Resources.LESS;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyGreatClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.GREAT;
            MainWindow.Encode += Resources.GREAT;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyLBracketClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.LBRACKET;
            MainWindow.Encode += Resources.LBRACKET;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyRBracketClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.RBRACKET;
            MainWindow.Encode += Resources.RBRACKET;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyLParenClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.LPAREN;
            MainWindow.Encode += Resources.LPAREN;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyRParenClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.RPAREN;
            MainWindow.Encode += Resources.RPAREN;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyNOTClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.NOT;
            MainWindow.Encode += Resources.NOT;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyORClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.OR;
            MainWindow.Encode += Resources.OR;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyANDClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.AND;
            MainWindow.Encode += Resources.AND;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyCommaClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.COMMA;
            MainWindow.Encode += Resources.COMMA;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyPlusClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.PLUS;
            MainWindow.Encode += Resources.PLUS;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        private void BtnKeyMinusClick(object sender, EventArgs e)
        {
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            txtExpression.Text += Resources.MINUS;
            MainWindow.Encode += Resources.MINUS;

            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

        internal void BtnCalcOKClick(object sender, EventArgs e)
        {
            // Clear Hint/Example
            lblHintText.Text = "";
            lblHint.Visible = false;
            lblExampleText.Text = "";
            lblExample.Visible = false;

            // Transfer Encoded to textbox
            var main = (MainWindow)Owner;
            main.UpdateExpr(txtExpression.Text);
        }

        private void BtnCalcClearClick(object sender, EventArgs e)
        {
            if (txtExpression.Text == "") return;

            while (MainWindow.undoBuffer.CanUndo)
            {
                MainWindow.undoBuffer.Undo();
                MainWindow.encodeBuffer.Undo();
            }

            txtExpression.Text = MainWindow.undoBuffer.Value;
            MainWindow.Encode = MainWindow.encodeBuffer.Value;

            lblHintText.Text = "";
            lblHint.Visible = false;
            lblExampleText.Text = "";
            lblExample.Visible = false;
        }

        private void BtnCalcUndoClick(object sender, EventArgs e)
        {
            lblHintText.Text = "";
            lblHint.Visible = false;
            lblExampleText.Text = "";
            lblExample.Visible = false;

            if (MainWindow.undoBuffer.CanUndo)
            {
                MainWindow.undoBuffer.Undo();
                MainWindow.encodeBuffer.Undo();
            }

            txtExpression.Text = MainWindow.undoBuffer.Value;
            MainWindow.Encode = MainWindow.encodeBuffer.Value;
        }

        private void BtnCalcRedoClick(object sender, EventArgs e)
        {
            lblHintText.Text = "";
            lblHint.Visible = false;
            lblExampleText.Text = "";
            lblExample.Visible = false;

            if (MainWindow.undoBuffer.CanUndo)
            {
                MainWindow.undoBuffer.Redo();
                MainWindow.encodeBuffer.Redo();
            }

            txtExpression.Text = MainWindow.undoBuffer.Value;
            MainWindow.Encode = MainWindow.encodeBuffer.Value;
        }

        private void ExprIdxChanged(object sender, EventArgs e)
        {
            // Clear Hint/Example
            lblHintText.Text = "";
            lblHint.Visible = false;
            lblExampleText.Text = "";
            lblExample.Visible = false;

            // Set undo buffer
            MainWindow.undoBuffer.SaveState();
            MainWindow.encodeBuffer.SaveState();

            // Set condition in textbox
            txtExpression.Text += comboExpr.Text;

            // Is_Timer_Ticking[x]
            if (comboExpr.Text == Resources.Is_Timer_Ticking)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.ITT1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.ITT1PEx;
                // Encode
                MainWindow.Encode += "a";
            }

            // Is_HP_Less[x.xx]
            if (comboExpr.Text == Resources.Is_HP_Less)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.IHPL1P;
                lblExample.Visible = true;
                switch (MainWindow.bDecimal)
                {
                    case true:
                        lblExampleText.Text = Resources.IHPL1PExPeriod;
                        break;

                    case false:
                        lblExampleText.Text = Resources.IHPL1PComma;
                        break;
                }
                // Encode
                MainWindow.Encode += "b";
            }

            // Is_Combat_Started[]
            if (comboExpr.Text == Resources.Is_Combat_Started)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.ICS0P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.ICS0PEx;
                // Encode
                MainWindow.Encode += "c[]";
            }

            // Randomize[x.xx]
            if (comboExpr.Text == Resources.Randomize)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.RND1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.RND1PEx;
                // Encode
                MainWindow.Encode += "d";
            }
            // Is_Target_Dead[]
            if (comboExpr.Text == Resources.Is_Target_Killed)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.ITK0P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.ITK0PEx;
                // Encode
                MainWindow.Encode += "e[]";
            }

            // Is_Dead[]
            if (comboExpr.Text == Resources.Is_Dead)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.ID0P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.ID0PEx;
                // Encode
                MainWindow.Encode += "h[]";
            }

            // Path_To[0]
            if (comboExpr.Text == Resources.Path_To)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.PT1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.PT1PEx;
                // Encode
                MainWindow.Encode += "i";
            }

            // More_Than[0]
            if (comboExpr.Text == Resources.More_Than)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.MT1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.MT1PEx;
                // Encode
                MainWindow.Encode += "j";
            }

            // Distance_To[0.00]
            if (comboExpr.Text == Resources.Distance_To)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.DT1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.DT1PEx;
                // Encode
                MainWindow.Encode += "k";
            }

            // Unknown12[]
            if (comboExpr.Text == Resources.Unknown12)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.U120P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.U120PEx;
                // Encode
                MainWindow.Encode += "l[]";
            }

            // Unknown13[]
            if (comboExpr.Text == Resources.Unknown13)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.U130P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.U130PEx;
                // Encode
                MainWindow.Encode += "m[]";
            }

            // Unknown14[]
            if (comboExpr.Text == Resources.Unknown14)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.U140P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.U140PEx;
                // Encode
                MainWindow.Encode += "n[]";
            }

            // Unknown15[]
            if (comboExpr.Text == Resources.Unknown15)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.U150P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.U150PEx;
                // Encode
                MainWindow.Encode += "o[]";
            }

            // Public_Counter[0]
            if (comboExpr.Text == Resources.Public_Counter)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.PC1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.PC1PEx;
                // Encode
                MainWindow.Encode += "q";
            }

            // Value[0]
            if (comboExpr.Text == Resources.Value)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.Val1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.Val1PEx;
                // Encode
                MainWindow.Encode += "p";
            }

            // Rank[0]
            if (comboExpr.Text == Resources.Rank)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.Rnk1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.Rnk1PEx;
                // Encode
                MainWindow.Encode += "r";
            }

            // Remove_Mob[0]
            if (comboExpr.Text == Resources.Remove_Mob)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.RM0P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.RM0PEx;
                // Encode
                MainWindow.Encode += "s[]";
            }

            // Cast_Skill[0]
            if (comboExpr.Text == Resources.Cast_Skill)
            {
                // Give Hint/Example
                lblHint.Visible = true;
                lblHintText.Text = Resources.CS1P;
                lblExample.Visible = true;
                lblExampleText.Text = Resources.CS1PEx;
                // Encode
                MainWindow.Encode += "t";
            }
            MainWindow.undoBuffer.Value = txtExpression.Text;
            MainWindow.encodeBuffer.Value = MainWindow.Encode;
        }

    }
}